package com.ruoyi.system.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 预算类别枚举（对应budgetType和finalBudgetType字段）
 */
@Getter
@AllArgsConstructor
@ApiModel(value = "BudgetTypeEnum", description = "预算类别枚举（1=基础项，2=升级项，3=增项）")
public enum BudgetTypeEnum {

    @ApiModelProperty(value = "基础项")
    BASE_ITEM(1, "基础项"),

    @ApiModelProperty(value = "升级项")
    UPGRADE_ITEM(2, "升级项"),

    @ApiModelProperty(value = "增项")
    ADD_ITEM(3, "增项");

    @EnumValue
    private final Integer code;

    @JsonValue
    private final String desc;

    /**
     * 根据code获取枚举
     */
    public static BudgetTypeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        return Arrays.stream(values())
                .filter(enumItem -> enumItem.code.equals(code))
                .findFirst()
                .orElse(null);
    }
}